<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-2-10
  Time: 下午1:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>退款申请审批</title>
    <script>
        $(function () {
            var status = $('[id^=status_]');
            for (var i = 0; i < status.length; i++) {
                if (status.eq(i).html() != "待审核") {
                    $('#refund_' + i).attr("href", "javascript:void(0)");
                    $('#fail_' + i).attr("href", "javascript:void(0)");
                }
            }

            $("#refundStatus").change(function () {
                $("tbody").empty();
                if ($(this).val() == "refunded") {

                } else if ($(this).val() == "noRefund") {

                } else if ($(this).val() == "rejected") {

                } else {

                }
            });

            $("#selectAll").click(function () {
                if ($(this).is(":checked")) {
                    $(":checkbox").prop("checked", "true");
                } else {
                    $(":checkbox").removeAttr("checked");
                }
            });
        });

        function refunded() {
            $.ajax({
                url: "/order/ajaxRefundData/refunded",
                dataType: "json",
                type: "get",
                success: function (data) {
                    $("tbody").html(data);
                }
            });
        }

        function noRefund() {
            $.ajax({
                url: "/order/ajaxRefundData/noRefund",
                dataType: "json",
                type: "get",
                success: function (data) {
                    $("tbody").html(data);
                }
            });
        }

        function rejected() {
            $.ajax({
                url: "/order/ajaxRefundData/rejected",
                dataType: "json",
                type: "get",
                success: function (data) {
                    $("tbody").html(data);
                }
            });
        }

        function unlimited() {
            $.ajax({
                url: "/order/ajaxRefundData/all",
                dataType: "json",
                type: "get",
                success: function (data) {
                    $("tbody").html(data);
                }
            });
        }

        function batchReFund() {
            var checkbox = $("[id^=sel_]");
            var reFundGuids = "";
            var count = 0;
            for (var i = 0; i < checkbox.length; i++) {
                if (checkbox.eq(i).is(":checked")) {
                    count += 1;
                }
            }
            if (count <= 0) {
                alert("选择有误!");
                return false;
            }
            for (var i = 0; i < checkbox.length; i++) {
                if (checkbox.eq(i).is(":checked")) {
                    if ($("#status_" + i).html() != "待审核") {
                        alert("选择有误!");
                        return false;
                    }
                    reFundGuids += checkbox.eq(i).val() + ",";
                }
            }
            window.location.href = "/order/doBatchReFund/" + reFundGuids;
        }


    </script>
</head>
<body>
<div>
    <%--退款状态:--%>
    <%--<select id="refundStatus">--%>
    <%--<option value="all">不限</option>--%>
    <%--<option value="noRefund">待审核</option>--%>
    <%--<option value="refunded">已退款</option>--%>
    <%--<option value="rejected">已驳回</option>--%>
    <%--</select>&nbsp;--%>
    <!-- Single button -->
    <div class="dropdown">
        <button type="button" class="btn btn-default dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
            退款状态 <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:unlimited()">不限</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:noRefund()">待审核</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:refunded()">已退款</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:rejected()">已驳回</a></li>
        </ul>&nbsp;
    <button class="btn btn-info" type="button" onclick="batchReFund()">批量退款</button>
    </div>

    <table class="table table-striped">
        <thead>
        <th width="5%" scope="col"><input type="checkbox" id="selectAll">全选</th>
        <th width="10%" scope="col">退款号</th>
        <th width="14%" scope="col">退款金额</th>
        <th width="10%" scope="col">退款原因</th>
        <th width="10%" scope="col">退款状态</th>
        <th width="14%" scope="col">退款操作</th>
        </thead>
        <tbody>
        <c:forEach items="${reFundDTOs}" var="reFundDTO" varStatus="status">
            <tr id="tr_${status.index}">
                <input type="hidden" id="guid_${status.index}" value="${reFundDTO.guid}">
                <td><input type="checkbox" value="${reFundDTO.guid}" id="sel_${status.index}"></td>
                <td>${reFundDTO.tradeNo}</td>
                <td>${reFundDTO.price}</td>
                <td>${reFundDTO.reason}</td>
                <td id="status_${status.index}">${reFundDTO.refundStatus}</td>
                <td><a href="/order/reject/${reFundDTO.guid}" id="fail_${status.index}">驳回</a>&nbsp;
                    <a href="/order/doReFund/${reFundDTO.guid}" id="refund_${status.index}">退款</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

</body>
</html>